<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        html,
        body,
        #app1 {
            width: 100%;
            height: 100%;
        }
        
        .wrapper {
            display: flex;
            justify-content: center;
            align-items: center;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.3);
            position: fixed;
            top: 0;
            left: 0;
        }
        
        .content {
            width: 220px;
            height: 160px;
            background-color: #fff;
        }
        
        .title {
            height: 40px;
            line-height: 40px;
            text-align: center;
        }
        
        .msg {
            display: flex;
            align-items: center;
            justify-content: center;
            box-sizing: border-box;
            padding: 5px 10px;
            border-top: 1px solid #eee;
            border-bottom: 1px solid #eee;
            height: 80px;
            text-align: center;
            color: gray;
            font-size: 14px;
        }
        
        .bottom {
            display: flex;
            height: 40px;
            line-height: 40px;
            text-align: center;
        }
        
        .bottom div {
            flex: 1;
            color: green;
        }
        
        .bottom div:nth-of-type(1) {
            border-right: 1px solid #eee;
            color: red;
        }
    </style>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>

<body>
    <div id="app1">
        <p>点击结果：{{clickResult}}</p>

        <!-- 2.设置子组件的自定义事件指定函数-->
        <wrapper :obj="textObj" @fn="setResult"></wrapper>

    </div>
</body>
<template id="temp">
    <div class="wrapper" v-if="show">
        <div class="content">
            <p class="title">{{obj.title}}</p>
            <div class="msg">{{obj.msg}}</div>
            <div class="bottom">
                <div @click="setResult(obj.cancelTxt)">{{obj.cancelTxt}}</div>
                <div @click="setResult(obj.submitTxt)">{{obj.submitTxt}}</div>
            </div>
        </div>
    </div>
</template>

<script>
    // 现有以上布局，把wrapper抽取成子组件，通过传值的方式往内部传递数据

    let wrapper = {
        template: '#temp',
        props: {
            obj: {
                type: Object,
                default: {}
            }
        },
        data() {
            return {
                show: true
            }
        },
        methods: {
            // 3.触发fn事件
            setResult(val) {
                this.$emit('fn', val)
                this.show = false
            }
        },
    }

    new Vue({
        el: '#app1',
        data: {
            textObj: {
                title: 'bug提示',
                msg: '亲，你还有53633个bug，是否要处理?',
                cancelTxt: '忽略，下班',
                submitTxt: '加班处理'
            },
            clickResult: ""
        },
        components: {
            wrapper
        },
        methods: {
            // 1.定义父组件改变数据方法
            setResult(val) {
                this.clickResult = val
            }
        },
    })
</script>

</html>